package top.kaoshanji.p1ch02c;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

/**
 * 代码清单 p1ch02c-16：MethodHandles.Lookup的查找字段使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/3 15:30
 */
public class MethodHandlesLookupExample03 {

    private static final Logger logger = LogManager.getLogger(MethodHandlesLookupExample03.class);

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        logger.info("...代码清单 p1ch02c-16：MethodHandles.Lookup的查找字段使用示例...");

        MethodHandles.Lookup lookup = MethodHandles.lookup();

        lookup.findGetter(MethodHandlesLookupSample.class, "name", String.class);
        lookup.findSetter(MethodHandlesLookupSample.class, "name", String.class);

        lookup.findStaticGetter(MethodHandlesLookupSample.class, "value", int.class);

        MethodHandle mh = lookup.findStaticSetter(MethodHandlesLookupSample.class, "value", int.class);

        System.out.println(mh.type());


    }

}
